<template>
  <div>
    <div class="c-item">
      <div class="c-wrapper">
        <span class="name">{{ comment.name }}:</span>
        <span class="content">{{ comment.content }}</span>
      </div>
      <div v-show="!isShow" class="addre" @click="add">添加回复</div>
      <div v-show="isShow" class="ipt-wrapper">
        <input v-model="msg" class="ipt" type="text">
        <button class="btn" @click="confirm">确认回复</button>
      </div>
    </div>
    <div v-if="comment.children && deep" class="pl">
      <div v-for="(item, index) in comment.children" :key="index">
        <comment :comment="item" :deep="false" @confirm="confirmChild" />
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Comment',
  props: {
    comment: Object,
    num: Number,
    deep: Boolean
  },
  data () {
    return {
      isShow: false,
      msg: ''
    }
  },
  methods: {
    add () {
      this.isShow = !this.isShow
    },
    confirm () {
      if (this.msg !== '' && this.msg.length !== 0) {
        // eslint-disable-next-line vue/require-explicit-emits
        this.$emit('confirm', this.msg, this.num)
        this.msg = ''
        this.isShow = !this.isShow
      } else {
        console.log('不允许为空')
      }
    },
    confirmChild (value) {
      // eslint-disable-next-line vue/require-explicit-emits
      this.$emit('confirm', value, this.num)
    }
  }
}
</script>

<style lang="scss" scoped>
.c-item{
    box-sizing: border-box;
    width: 100%;
    .addre{
      padding-bottom:10px;
    }
    .c-wrapper{
        height: 40px;
        line-height: 40px;
    }
    .addre:last-of-type{
      padding-bottom: 10px;
    }
    .ipt-wrapper{
        padding: 6px;
        display: flex;
        .ipt{
            padding-left: 5px;
            height: 33px;
            line-height: 33px;
            border-radius: 4px;
            font-size: 16px;
            border: none;
            border: 1px solid #ccc;
            flex: 4;
        }
        .ipt:focus{
          box-shadow: 0px 0px 3px #000
        }
        .btn{
            flex: 1;
            color: #333;
            background-color: #fff;
            border-color: #ccc;
            border-radius: 4px;
            outline: none;
            border: 1px solid #ccc;
            margin-left: 4px;
        }
    }
    .addre{
      font-size: 12px;
      color: blue;
      cursor: pointer;
    }
}
.pl{
  padding-left: 10px;
  margin-top: 10px;
  border-top: 1px solid #ccc;
  background-color: #f7f7f7;
}
</style>
